// timerWorker.js
let timerId
let elapsedTime = 0

self.onmessage = function (e) {
  const { action, duration } = e.data

  if (action === 'start') {
    elapsedTime = 0 // 重置计时
    timerId = setInterval(() => {
      elapsedTime += 1000 // 每秒增加
      self.postMessage(elapsedTime) // 发送时间更新
    }, 1000)
  } else if (action === 'stop') {
    clearInterval(timerId)
  }
}
